class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        set<int> set;
        vector<int> rst;

        for(int nums : nums1){
            set.insert(nums);
        }

        for(int nums : nums2){
            auto it = set.find(nums);
            if(it != set.end()){
                rst.push_back(nums);
                set.erase(it);
            }
        }

        return rst;
    }
};